<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../js/vue.js"></script>

    <style>

        .tab ul{
            padding: 0;
            margin: 0;
            overflow: hidden;

        }

        .tab ul li {
            list-style: none;
            width: 100px;
            height: 45px;
            line-height: 45px;
            float: left;
            text-align: center;
            border: 1px solid red;
            cursor: pointer;

        }

        .tab ul li.active {
            background-color: orange;
        }

        .tab div {
            display: none;
            width: 500px;
            height: 300px;
            border: 1px solid pink;
        }

        .tab div.currentselect{
            display: block;
        }

    </style>

</head>
<body>

<div id="div1">

    <div class="tab">

        <ul>
            <li @click='changeTabIndex(index)' :class='currentIndex==index?"active":""' v-for="(item,index) in products">{{item.name}}</li>

        </ul>
        
        <div :class='currentIndex==index?"currentselect":""' v-for="(item,index) in products" >
            <img :src="item.path">
        </div>

    </div>

</div>


<script>
    const vueObj = new Vue({
        el: "#div1",
        data: {
            currentIndex: 0,
            products:[
                {
                    id: 1,
                    name: "笔记本电脑",
                    path:"img/pc.png"
                },
                {
                    id: 2,
                    name: "厨具",
                    path:"img/chuju.png"
                },
                {
                    id: 3,
                    name: "家电",
                    path:"img/jiadian.png"
                },
            ]
        },

        methods: {
            changeTabIndex: function (index) {
                this.currentIndex = index;
            },
        },



    });

</script>
</body>
</html>